﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ASPItalia.ModelVirtualCasting.EntityFramework.Wrappers;
using System.Linq.Expressions;
using System.Collections.ObjectModel;
using System.Data.Entity;

namespace ASPItalia.ModelVirtualCasting.Web.Tests.Utils
{
	public class FakeDbSet<T> : IDbSet<T> where T : class
	{
		private List<T> innerList = new List<T>();
		public List<T> InnerList
		{
			get { return this.innerList; }
		}

		public FakeDbSet()
		{
		}

		public FakeDbSet(IEnumerable<T> items)
		{
			this.innerList = new List<T>(items);
		}

		public T Add(T entity)
		{
			this.innerList.Add(entity);
			return entity;
		}

		public T Attach(T entity)
		{
			if (!this.innerList.Contains(entity))
				this.innerList.Add(entity);

			return entity;
		}

		public T Remove(T entity)
		{
			return entity;
		}

		public ObservableCollection<T> Local
		{
			get { return new ObservableCollection<T>(this.innerList); }
		}

		public T Find(params object[] keyValues)
		{
			return null;
		}

		public T Create()
		{
			return null;
		}

		public TDerived Create<TDerived>() where TDerived : class, T
		{
			return null;
		}


		#region IEnumerable<T> Members

		public IEnumerator<T> GetEnumerator()
		{
			return this.innerList.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return this.innerList.GetEnumerator();
		}

		#endregion

		#region IQueryable Members

		public Type ElementType
		{
			get { return typeof(T); }
		}

		public Expression Expression
		{
			get { return this.innerList.AsQueryable().Expression; }
		}

		public IQueryProvider Provider
		{
			get { return this.innerList.AsQueryable().Provider; }
		}

		#endregion
	}
}